var t = require;
var i = module;
cc.Class({
    extends: cc.Component,
    properties: {
        getRewardBtn:cc.Node,           //奖励按钮
        getRewardBtnLabel:cc.Label,     
        openSideBtn:cc.Node,            //打开按钮
        closeSideBtn:cc.Node,           //关闭按钮
    },
    onLoad: function () {
        this.getRewardBtn.on(cc.Node.EventType.TOUCH_START, this.getButtonCallBack, this);
        this.closeSideBtn.on(cc.Node.EventType.TOUCH_START, this.onCloseSideNode, this);
        //this.openSideBtn.on(cc.Node.EventType.TOUCH_START, this.onOpenSideNode, this);        //无效，打开才会添加事件

       this.onRefresh();
    },

    onRefresh(){
        AD_TouTiao.isSideEnter= cc.sys.localStorage.getItem("isSidEnter");
        
        this.getRewardBtnLabel.string = AD_TouTiao.isSideEnter?"领取奖励":"前往侧边栏";

        var isSidReward =  cc.sys.localStorage.getItem("isSidReward"); 
        if (isSidReward){
            this.getRewardBtnLabel.string = "奖励已领取";
            this.getRewardBtn.interactable = false;
            this.openSideBtn.active = false;
        }
    },
    onOpenSideNode(){
        this.node.active = true;
    },

    onCloseSideNode(){
        this.node.active = false;
    },

    getButtonCallBack : function () {
        if (AD_TouTiao.isSideEnter){
            AD_TouTiao.freeAdNum = 3;
            cc.sys.localStorage.setItem("isSidReward", true);
        }else{
            AD_TouTiao.navigateToScene();
        }
        this.onRefresh();
    },

});
